/**
 * @method timeFormat 时间格式化
 * @param
 * @return status
 */
export const timeFormatFilter = (value, format) => {
  if (!value) {
    return "";
  }
  let date = new Date(value);
  let y = date.getFullYear();
  let m = date.getMonth() + 1;
  let d = date.getDate();
  let h = date.getHours();
  let min = date.getMinutes();
  let s = date.getSeconds();
  let result = "";
  if (format == undefined) {
    result = `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d} ${
      h < 10 ? "0" + h : h
    }:${min < 10 ? "0" + min : min}:${s < 10 ? "0" + s : s}`;
  }
  if (format == "yyyy-mm-dd") {
    result = `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d}`;
  }
  if (format == "yyyy年mm月dd日") {
    result = `${y}年${m < 10 ? "0" + m : m}月${d < 10 ? "0" + d : d}日`;
  }
  if (format == "yyyy年mm月") {
    result = `${y}年${m < 10 ? "0" + m : m}月`;
  }
  if (format == "yyyy-mm") {
    result = `${y}-${m < 10 ? "0" + m : m}`;
  }
  if (format == "mm-dd") {
    result = ` ${mm < 10 ? "0" + mm : mm}:${ddmin < 10 ? "0" + dd : dd}`;
  }
  if (format == "hh:mm") {
    result = ` ${h < 10 ? "0" + h : h}:${min < 10 ? "0" + min : min}`;
  }
  if (format == "yyyy") {
    result = `${y}`;
  }
  return result;
};

/**
 * 判断日期相隔时间
 * @param {*} dateString1
 * @param {*} dateString2
 */
function getDaysBetween(startDate, endDate) {
  var days = (endDate - startDate) / (1 * 24 * 60 * 60 * 1000);
  // alert(days);
  return parseFloat(days.toFixed(2));
}

/**
 * @method contractAuditStateFilter 审核状态过滤
 * @param
 * @return status
 */
export const contractAuditStateFilter = (
  contractAuditState,
  contractState,
  date
) => {
  contractAuditState += "";
  contractState += "";
  //已生效 && 未终止 && 剩余天数 < 90
  if (
    contractAuditState == "2" &&
    contractState == "1" &&
    getDaysBetween(new Date().getTime(), new Date(date).getTime()) < 90
  ) {
    return "已生效(待续签)";
  }

  // 未通过
  if (contractAuditState == "1") {
    return "待审核(未通过)";
  }

  switch (contractState) {
    case "0":
      return "待生效";
      break;
    case "1":
      return "已生效";
      break;
    case "2":
      return "已终止";
      break;
    case "3":
          return "未审核";
        break;
    default:
      return contractState;
      break;
  }
};

/**
 * @method contractFilter 合同状态过滤
 * @param
 * @return status
 */
export const contractFilter = value => {
  switch (value + "") {
    case "0":
      return "待生效";
      break;
    case "1":
      return "已生效";
      break;
    case "2":
      return "已终止";
      break;
    default:
      return value;
      break;
  }
};

/**
 * @method auditOpinionFilter 审核意见过滤
 * @param
 * @return status
 */
export const auditOpinionFilter = value => {
  switch (value + "") {
    case "1":
      return "不通过";
      break;
    case "2":
      return "通过";
      break;
    default:
      return value;
      break;
  }
};

/**
 * @method  承租人
 * @param
 * @return status
 */
export const tenantTypeFilter = value => {
  switch (value + "") {
    case "0":
      return "个人";
      break;
    case "1":
      return "企业";
      break;
    default:
      return value;
      break;
  }
};

/**
 * @method  房间状态
 * @param
 * @return status
 */
export const roomStatusFilter = value => {
  switch (value + "") {
    case "0":
      return "空置";
      break;
    case "1":
      return "已出租";
      break;
    case "2":
      return "自用";
      break;
    default:
      return value;
      break;
  }
};

/**
 * @method  房间朝向
 * @param
 * @return status
 */
export const roomFacingFilter = value => {
  switch (value + "") {
    case "0":
      return "东";
      break;
    case "1":
      return "南";
      break;
    case "2":
      return "西";
      break;
    case "3":
      return "北";
      break;
    default:
      return value;
      break;
  }
};

/**
 * @method  房间朝向
 * @param
 * @return status
 */
export const houseTypeFilter = value => {
  switch (value + "") {
    case "0":
      return "普通住宅";
      break;
    case "1":
      return "商用办公";
      break;
    default:
      return value;
      break;
  }
};

/**
 * @method  费用系数状态
 * @param
 * @return status
 */
export const costFactorStatusFilter = value => {
  switch (value + "") {
    case "0":
      return "正常";
      break;
    case "1":
      return "已终止";
      break;
    default:
      return value;
      break;
  }
};

/**
 * @method  缴费方式
 * @param
 * @return status
 */
export const paymentMethodFilter = value => {
  switch (value + "") {
    case "0":
      return "线上缴费";
      break;
    case "1":
      return "线下缴费";
      break;
    default:
      return value;
      break;
  }
};

/**
 * @method  抄表状态
 * @param
 * @return status
 */
export const meterReadingStatusFilter = value => {
  switch (value + "") {
    case "0":
      return "待抄表";
      break;
    case "1":
      return "已抄表";
      break;
    default:
      return value;
      break;
  }
};

/**
 * @method  缴费状态
 * @param
 * @return status
 */
export const paymentStatusFilter = value => {
  switch (value + "") {
    case "0":
      return "待缴费";
      break;
    case "1":
      return "已缴费";
      break;
    default:
      return value;
      break;
  }
};

/**
 * @method  缴费情况
 * @param
 * @return status
 */
export const paymentFilter = value => {
  switch (value + "") {
    case "0":
      return "正常缴费";
      break;
    case "1":
      return "已欠费";
      break;
    default:
      return value;
      break;
  }
};

/**
 * @method  开票方式
 * @param
 * @return status
 */
export const invoiceMethodFilter = value => {
  switch (value + "") {
    case "0":
      return "线上开票";
      break;
    case "1":
      return "线下开票";
      break;
    default:
      return value;
      break;
  }
};

/**
 * @method  发票状态
 * @param
 * @return status
 */
export const invoiceStatusFilter = (value,monthlyInvoiceStatus) => {
  value = value + "";
  monthlyInvoiceStatus = monthlyInvoiceStatus + "";
  
  // 都成功就已开票
  if( value=='1' && monthlyInvoiceStatus=='1' ){
      return "已开票";
  }
  // 一个还在开票中 就开票中
  if(value=='2'||monthlyInvoiceStatus=='2'){
      return "开票中";
  }
  
  if(value=='0'||monthlyInvoiceStatus=='0'){
      return "待开票";
  }
  
  return ""
  
};

/**
 * 房间用途
 */
export const roomPurposeFilter = value => {
  switch (value + "") {
    case "43":
      return "商用";
      break;
    case "44":
      return "住宅";
      break;
    default:
      return value;
      break;
  }
};

/**
 * 工单状态
 */
export const workOrderStatusFilter = value => {
  switch (value + "") {
    case "0":
      return "待处理";
      break;
    case "1":
      return "已处理";
      break;
    default:
      return value;
      break;
  }
};

/**
 * 线路状态
 */
export const deviceStatusFilter = value => {
  switch (value + "") {
    case "0":
      return "正常";
      break;
    case "1":
      return "故障";
      break;
    case "2":
      return "报警";
    case "3":
      return "故障和报警";
    default:
      return value;
      break;
  }
};

/**
 * 通用过滤
 * @param {} params
 * @param {*} array
 */
export const commonFilter = function(params, array) {
  let arrObj = array.filter(v => {
    return v.pkBasicdataId === params;
  });
  if (arrObj && arrObj.length > 0) {
    return arrObj[0].itemName;
  } else return params;
};
